home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group03a.txt / 000075_icon-group-sender_Wed Apr 16 11:58:31 2003.msg < prev    next >
Internet Message Format  |  2003-12-22  |  1KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id h3GIvO608433
  4.     for icon-group-addresses; Wed, 16 Apr 2003 11:57:24 -0700 (MST)
  5. Message-Id: <200304161857.h3GIvO608433@baskerville.CS.Arizona.EDU>
  6. Date: Wed, 16 Apr 2003 11:09:39 +1200 (NZST)
  7. From: "Richard A. O'Keefe" <ok@cs.otago.ac.nz>
  8. To: icon-group@cs.arizona.edu, rlb@hoekstra-uitgeverij.nl
  9. Subject: Re: Simplifying Integer Arithmetic
  10. X-scanner: scanned by Inflex 1.0.12.4 - (http://pldaniels.com/inflex/)
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: RO
  13.  
  14. Richard Bos <rlb@hoekstra-uitgeverij.nl>
  15. explained about / and % in C89 and C99.
  16.  
  17. However, it is worth pointing out that the C89 standarisers
  18. were aware of the issue.  They chose to deal with it not by
  19. requiring incompatible changes to existing compilers (like
  20. they did with signed@unsigned combinations) but by adding a
  21. pair of library functions:
  22.     div(int n, int d) => a div_t containing quotient and remainder
  23.     ldiv(long n, long d) => an ldiv_t containing quotient and remainder
  24. where the quotient is sign(n/d)*floor(abs(n/d)).
  25.  
  26. So if you want a fully specified truncate-towards-zero quotient
  27. and/or remainder in C89, you use div() or ldiv() depending on the
  28. size of the operands.
  29.  
  30.